<html>
<head><meta charset="utf-8"><title>optimizing closure size · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html">optimizing closure size</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242632965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242632965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242632965">(Jun 14 2021 at 17:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281950">Aman Arora</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/status.20sync/near/242037584">said</a>:</p>
<blockquote>
<p>One interesting possibility though is if we have an immutable ref, then any precise path starting at that would also be an immutable ref and therefore we should be able to capture that ref on its own</p>
</blockquote>
<p>Ah, this is interesting <span class="user-mention" data-user-id="281950">@Aman Arora</span></p>



<a name="242632981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242632981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242632981">(Jun 14 2021 at 17:32)</a>:</h4>
<p>I'm debating about it</p>



<a name="242632995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242632995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242632995">(Jun 14 2021 at 17:32)</a>:</h4>
<p>OK, it seems right</p>



<a name="242633018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242633018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242633018">(Jun 14 2021 at 17:32)</a>:</h4>
<p>The idea is specifically that we are borrowing the referent of a shared ref</p>



<a name="242633035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242633035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242633035">(Jun 14 2021 at 17:32)</a>:</h4>
<p>Do you have any idea how often that might apply? It seems simple enough to test</p>



<a name="242633089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242633089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242633089">(Jun 14 2021 at 17:33)</a>:</h4>
<p>Can you open an issue to track it?</p>



<a name="242633833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242633833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242633833">(Jun 14 2021 at 17:38)</a>:</h4>
<p>I'll create an issue</p>



<a name="242639971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242639971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242639971">(Jun 14 2021 at 18:27)</a>:</h4>
<p>Also it will either be a referant or a copy, and in either cases copying the root vraiable completely would be cheaper</p>



<a name="242812407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242812407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242812407">(Jun 15 2021 at 23:27)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> this isn't true for e.g. <code>&amp;u8</code>, right?</p>



<a name="242818275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242818275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242818275">(Jun 16 2021 at 00:55)</a>:</h4>
<p>Well not for &amp;u8, because the it's still the size of a reference, but if it was u8 it would be cheaper -- but that's not the optimizaiton I'm suggesting.</p>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2021&amp;gist=253a347e4d588920f334d956a5e513b4">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2021&amp;gist=253a347e4d588920f334d956a5e513b4</a></p>
<p>In this example closure captures an &amp;u8 and the size of the closure is 8 bytes, which is size of the reference.</p>



<a name="242818551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242818551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242818551">(Jun 16 2021 at 00:59)</a>:</h4>
<p>The only time we will have a ByValue(Copy) in case of x.y.z (where x is some shared ref) is in case of a move closure. </p>
<p>In such a case there is a possiblity that copying x.y.z is cheaper than copying x</p>



<a name="242936192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/242936192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#242936192">(Jun 16 2021 at 20:11)</a>:</h4>
<p><a href="https://hackmd.io/hpjgfcwaSK20uFtZibwhIw">https://hackmd.io/hpjgfcwaSK20uFtZibwhIw</a></p>



<a name="243626759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243626759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243626759">(Jun 23 2021 at 09:29)</a>:</h4>
<p>This worked hillariously well </p>
<p><a href="https://docs.google.com/spreadsheets/d/1zOOeTFz4AvprEVsiPNFlkt4x_93N7WQe2uv2pX3BzXQ/edit?usp=sharing">https://docs.google.com/spreadsheets/d/1zOOeTFz4AvprEVsiPNFlkt4x_93N7WQe2uv2pX3BzXQ/edit?usp=sharing</a></p>



<a name="243626852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243626852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243626852">(Jun 23 2021 at 09:30)</a>:</h4>
<p>I haven't done a baseline compare again, but don't expect any major changes in the overall trend</p>



<a name="243626876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243626876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243626876">(Jun 23 2021 at 09:30)</a>:</h4>
<p>for comparison this was the original: <a href="https://docs.google.com/spreadsheets/d/1zNWWvTQ9kd0TDraNY_55HFDbHMaBl1NZn8chi30_M4g/edit#gid=845050938">https://docs.google.com/spreadsheets/d/1zNWWvTQ9kd0TDraNY_55HFDbHMaBl1NZn8chi30_M4g/edit#gid=845050938</a></p>



<a name="243627023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243627023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243627023">(Jun 23 2021 at 09:32)</a>:</h4>
<p>I did the run on <code>syn</code> crate and we had no increase after the optimization.</p>



<a name="243627080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243627080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243627080">(Jun 23 2021 at 09:33)</a>:</h4>
<p>Cargo doesn't seem to build for me locally on latest nightly, but CI seems to be passing on the cargo repo so I need to look into that</p>



<a name="243697328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243697328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243697328">(Jun 23 2021 at 18:59)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> this is the "just capture the base reference" optimization?</p>



<a name="243697350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243697350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243697350">(Jun 23 2021 at 18:59)</a>:</h4>
<p>that's awesome news!</p>



<a name="243697416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243697416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243697416">(Jun 23 2021 at 19:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/optimizing.20closure.20size/near/243697328">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="281950">Aman Arora</span> this is the "just capture the base reference" optimization?</p>
</blockquote>
<p>yes</p>



<a name="243697472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243697472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243697472">(Jun 23 2021 at 19:00)</a>:</h4>
<p>I'm running a base line again right now, hopefully we will have data before we meet.</p>



<a name="243700852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243700852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243700852">(Jun 23 2021 at 19:30)</a>:</h4>
<p>Here is the base line i did again today: <a href="https://docs.google.com/spreadsheets/d/1U5vaXu490wn8Ae1LB1mSfoP_EZrGRHbUU6ADbeY8bn4/edit#gid=545238654">https://docs.google.com/spreadsheets/d/1U5vaXu490wn8Ae1LB1mSfoP_EZrGRHbUU6ADbeY8bn4/edit#gid=545238654</a></p>



<a name="243700861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/243700861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#243700861">(Jun 23 2021 at 19:30)</a>:</h4>
<p>There is a one off eerror that I'm not sure about</p>



<a name="244093160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244093160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244093160">(Jun 28 2021 at 00:50)</a>:</h4>
<p>So the optimization didn't work on the edge case for the reason <code>'a must outlive 'static</code>. The implementation is doing what we expected it to I checked that by dumping the capture ananlysis.</p>
<p>To understand what's happneing I wrote this which doesn't seem to work pre optimization:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">B</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">i32</span><span class="p">);</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyStruct</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="n">a</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="nb">static</span> <span class="kt">str</span><span class="p">,</span><span class="w"></span>
<span class="w">   </span><span class="n">b</span>: <span class="nc">B</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;'</span><span class="na">a</span><span class="p">,</span><span class="w"> </span><span class="o">'</span><span class="na">b</span><span class="o">&gt;</span><span class="p">(</span><span class="n">m</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="nc">MyStruct</span><span class="o">&lt;'</span><span class="na">b</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">'</span><span class="nb">static</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nb">drop</span><span class="p">(</span><span class="o">&amp;</span><span class="n">m</span><span class="p">.</span><span class="n">a</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">c</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="244093186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244093186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244093186">(Jun 28 2021 at 00:51)</a>:</h4>
<p>I suppose I do not understand lifetimes well enough to figure out why it's failng, but I get the same error</p>
<div class="codehilite"><pre><span></span><code>17 |     c
   |     ^ returning this value requires that `&#39;a` must outlive `&#39;static`
   |
   = help: consider replacing `&#39;a` with `&#39;static`
</code></pre></div>



<a name="244093255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244093255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244093255">(Jun 28 2021 at 00:53)</a>:</h4>
<p>capture analysis shows that what's being captured is <code>m[Deref,(0, 0)] -&gt; ImmBorrow</code></p>



<a name="244093269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244093269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244093269">(Jun 28 2021 at 00:54)</a>:</h4>
<p>Is the reason that we are captuing a reference toa reference and so the life time of the capture is lifetime of the root variable = 'a?</p>



<a name="244093329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244093329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244093329">(Jun 28 2021 at 00:55)</a>:</h4>
<p>In which case the solution might be if we have a shared ref as the type of the captured place then captured the reference ByValue (I assume this would be a Copy because shared ref and therefore the same size other than in case of function pointers)</p>



<a name="244155856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244155856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244155856">(Jun 28 2021 at 14:47)</a>:</h4>
<p>Yes, I think we discussed this last week, <span class="user-mention" data-user-id="281950">@Aman Arora</span> ?</p>



<a name="244155886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244155886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244155886">(Jun 28 2021 at 14:47)</a>:</h4>
<p>That we only want to remove <em>trailing fields</em></p>



<a name="244155892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244155892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244155892">(Jun 28 2021 at 14:48)</a>:</h4>
<p>and not trailing derefs</p>



<a name="244173652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244173652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244173652">(Jun 28 2021 at 16:54)</a>:</h4>
<p>Ah right, my bad</p>



<a name="244185797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244185797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244185797">(Jun 28 2021 at 18:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <br>
PR for the profile command: <a href="https://github.com/rust-lang/rust/pull/86695">https://github.com/rust-lang/rust/pull/86695</a></p>



<a name="244205102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing%20closure%20size/near/244205102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/optimizing.20closure.20size.html#244205102">(Jun 28 2021 at 21:10)</a>:</h4>
<p>PR for the optimization: <a href="https://github.com/rust-lang/rust/pull/86701">https://github.com/rust-lang/rust/pull/86701</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>